<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <el-form  border :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" highlight-current-row>
          <el-form-item label="项目名称" prop="projectName">
            <el-input
              v-model="queryParams.projectName"
              placeholder="请输入项目名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <div style="width: 100%;height: 90vh;overflow:auto; margin-bottom: 30%;padding-bottom: 18%;position: relative;">
        <el-table v-loading="loading" :data="purchasingList" :row-style="{ height: '25px' }"  :cell-style="{ padding: '0px' }" height="450" highlight-current-row>
          <el-table-column label="审核状态" align="center" prop="examineStatus" :show-overflow-tooltip="true"/>
          <el-table-column label="采购编号" align="center" prop="purchasingNo" :show-overflow-tooltip="true"/>
          <el-table-column label="建立时间" align="center" prop="establishTime" width="110">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.establishTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="供应商" align="center" prop="supplier" :show-overflow-tooltip="true"/>
          <el-table-column label="客户名称" align="center" prop="enterpriseName" :show-overflow-tooltip="true"/>
          <el-table-column label="项目编号" align="center" prop="projectNo" :show-overflow-tooltip="true"/>
          <el-table-column label="项目名称" align="center" prop="projectName" :show-overflow-tooltip="true"/>
          <el-table-column label="计划时间" align="center" prop="planTime" width="110">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.planTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="完成时间" align="center" prop="completeTime" width="110">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.completeTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="费用" align="center" prop="fee" :show-overflow-tooltip="true"/>
          <el-table-column label="状态" align="center" prop="status"  >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.procure_status" :value="scope.row.status"/>
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center" prop="num" />
          <el-table-column label="单价" align="center" prop="unitPrice" />
          <el-table-column label="总价" align="center" prop="totalPrice" />
          <el-table-column label="开户银行" align="center" prop="bankName" :show-overflow-tooltip="true"/>
          <el-table-column label="开户账号" align="center" prop="bankNo" :show-overflow-tooltip="true"/>
          <el-table-column label="附件" align="center" prop="fileUpload" >
            <template slot-scope="scope">
              <el-button @click.stop="handlePictureCardPreview(scope.row.fileUpload)" size="small" v-if="scope.row.fileUrl!==null"
                         type="text">附件</el-button>
              <el-button size="small" v-else type="text">无附件</el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-circle-check"
                @click="handleApproved(scope.row)"
                title="审核通过"
                v-if="scope.row.examineStatus!='审核通过'"
              ></el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-circle-close"
                @click="handleRepulse(scope.row)"
                title="打回"
                v-if="scope.row.examineStatus!='审核通过'"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
        </div>
      </el-col>
    </el-row>
    <!--    附件展示对话框-->
    <el-dialog title="查看附件" :visible.sync="openFileList" width="500px" append-to-body v-if="openFileList">
      <UploadFile :upload-id="uploadId" :business-code="businessCode"></UploadFile>
    </el-dialog>
  </div>
</template>

<script>
import { listPurchasingExamine, Approved, repulse, addPurchasing, updatePurchasing } from "@/api/procure/purchasing";
import MainType from "../../../components/MainType/index.vue";
import {listType} from "@/api/maintype/type";
import UploadFile from "../../upload/index.vue";
export default {
  name: "Purchasing",
  components: {UploadFile, MainType},
  dicts: ['procure_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //附件对话框
      openFileList:false,
      uploadId:null,
      businessCode:'procure',
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购管理表格数据
      purchasingList: [],
      // 弹出层标题
      title: "",
      typeCode:'procure',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        projectName: null,
        classificationId:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采购管理列表 */
    getList() {
      this.loading = true;
      listPurchasingExamine(this.queryParams).then(response => {
        this.purchasingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    //获取树节点数据
    listType(){
      listType({typeCode:'procure'}).then(res=>{
        console.log(this.options)
        this.options=res.data;
      })
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //树点击事件
    getNode(data){
      console.log(data)
      if(data.parentId!=='00000000-0000-0000-0000-000000000000'){
        this.queryParams.classificationId=data.id
      }else {
        this.queryParams.classificationId=null;
      }
      this.getList()
    },
    handleApproved(row){
      this.$confirm('是否将数据审核通过?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
       Approved(row.id).then(res=>{
         this.$message.success("审核通过");
         this.getList();
       })
      });
    },
    handlePictureCardPreview(id) {
      this.uploadId=id;
      this.openFileList = true;
    },
    handleRepulse(row){
      this.$confirm('是否将数据打回?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        repulse(row.id).then(res=>{
          this.$message.success("成功打回");
          this.getList();
        })
      });
    }
  }
};
</script>
